using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ClientTools.Client.Controls.Media.Dialogs
{
    public partial class AddImageDialog : Form
    {
        public AddImageDialog()
        {
            InitializeComponent();
        }

        private void OK_Button_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void Cancel_Button_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void cmdAddImage_Click(object sender, EventArgs e)
        {
            if (this.OpenFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                foreach (string s in this.OpenFileDialog1.FileNames)
                {
                    if (!this.IsAllreadyInList(s))
                    {
                        this.lbxImages.Items.Add(s);
                    }
                }
            }
        }

        private bool IsAllreadyInList(string s)
        {
            foreach (string li in this.lbxImages.Items)
            {
                if (li == s)
                {
                    return true;
                }
            }
            return false;
        }

        private void cmdRemoveSelectedItems_Click(object sender, EventArgs e)
        {
            string[] s = new string[this.lbxImages.SelectedItems.Count - 1];
            for (int i = 0; i < this.lbxImages.SelectedItems.Count; i++)
            {
                s[i] = (string)this.lbxImages.SelectedItems[i];
            }
            for (int i = 0; i < s.Length; i++)
            {
                this.lbxImages.Items.Remove(s[i]);
            }
        }

        private void AddImageDialog_Load(object sender, EventArgs e)
        {
            this.Label1.Text = "Select the image(s)";
        }

        public int MaxImageSize 
        { 
            get 
            {
                if (this.nudMaxSize.Value == 0)
                {
                    return 800;
                }
                else
                {
                    return (int)this.nudMaxSize.Value;
                }
            } 
        }
    }
}